﻿using System;
using System.Web.Mvc;


namespace BlueSky.Web.Common
{
    public static class Utils
    {
        public static string GetControllerName(object instance)
        {
            return GetControllerName(instance.GetType());
        }

        public static string GetControllerName<TControllerType>()
        {
            return GetControllerName(typeof(TControllerType));
        }

        public static string GetControllerName(Type controllerType)
        {
            string controllerName = controllerType.Name;
            int nameIndex = controllerName.LastIndexOf("Controller");
            if (nameIndex > 0)
            {
                controllerName = controllerName.Substring(0, nameIndex);
            }
            return controllerName;
        }
    }
}
